<?php 

class Order extends CI_Model {

	function getLastOrderId()
	{
		$qr = $this->db->query('SELECT order_id FROM order ORDER BY order_id DESC LIMIT 1');
		$id = 0;
		
		foreach($qr->result() as $order)
		{
			$id = $order->order_id;
		}
		
		return $id;
	}
	
	function getOrder()
	{
		$ret = array();
		//for each order
		$query = $this->db->get('client-order');
		$i = 1;
		foreach($query->result() as $order)
		{
			$info['id'] = $order->id_order;
			//find client name 
			$qr = $this->db->query('SELECT * FROM client WHERE id = '.$order->id_client.' ');
			
			foreach($qr->result() as $client)
			{
				$info['name'] = $client->client;
			}
			
			//find total for order
			$qr2 = $this->db->query('SELECT * FROM
			`order` 
			WHERE 
			order_id 
			= 
			'.$order->id_order.' ');
			$total = 0;
			foreach($qr2->result() as $ord)
			{
				//count total
				$total += $ord->price*$ord->quantity;
			}
			
			$info['total'] = $total;
			$info['date'] = $order->date;
			
			$ret[$i] = $info;
			$i++;
		}
	
	
		return $ret;
	}


}

?>